﻿using System;
using System.IO;

namespace UnionnetClient.Model
{
	static internal class AppLog
	{
		static AppLog()
		{
			System.Diagnostics.Debug.WriteLine(filePath);
		}

		static string LogFile
		{
			get { return filePath; }
			set { filePath = value; }
		}

		public static void InfoLog(string message)
		{
			Log("INF", message);
		}

		public static void ErrorLog(string message)
		{
			Log("ERR", message);
		}

		public static void EventLog(string message)
		{
			Log("EVT", message);
		}

		public static void Log(string type, string message)
		{
			using(FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
			{
				fs.Seek(fs.Length, SeekOrigin.Begin);		
				using (StreamWriter sw = new StreamWriter(fs))
				{
					sw.WriteLine("[{0}] [{1}] {2}", type, DateTime.Now.ToString("MM-dd HH:mm:ss"), message.Replace("\n", "<CR> "));
				}
			}
		}

		static private string filePath = Path.Combine(AppEnvironment.AppDataFolder,
			string.Format("uc{0}{1}-{2}.log", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(), Environment.UserName));
	}
}
